﻿Public Class RelayCommand
  Implements ICommand

#Region "Fields"

  ReadOnly _execute As Action(Of Object)
  ReadOnly _canExecute As Predicate(Of Object)

#End Region

#Region "Constructors"

  Public Sub New(execute As Action(Of Object))
    Me.New(execute, Nothing)
  End Sub

  Public Sub New(execute As Action(Of Object), canExecute As Predicate(Of Object))
    If execute Is Nothing Then
      Throw New ArgumentNullException("execute")
    End If

    _execute = execute
    _canExecute = canExecute
  End Sub
#End Region

#Region "ICommand Members"

  <DebuggerStepThrough> _
  Public Function CanExecute(parameter As Object) As Boolean Implements ICommand.CanExecute
    Return If(_canExecute Is Nothing, True, _canExecute(parameter))
  End Function

  Public Event CanExecuteChanged(sender As Object, e As EventArgs) Implements ICommand.CanExecuteChanged
  '  AddHandler(ByVal value As EventHandler)
  '    CommandManager.RequerySuggested += value
  '  End AddHandler
  '  RemoveHandler(ByVal value As EventHandler)
  '    CommandManager.RequerySuggested -= value
  '  End RemoveHandler
  'End Event

  Public Sub Execute(parameter As Object) Implements ICommand.Execute
    _execute(parameter)
  End Sub

#End Region

End Class
